Lift the requirement that cargo is built with make
authorAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 03:54:32 +0000 (20:54 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 03:54:32 +0000 (20:54 -0700)
Cargo should be able to build with cargo so others can depend on the cargo
library. This means that the one requirement of the CFG_VERSION env var will not
be available. This alters `version()` to prioritize CFG_VERSION but fall back to
the cargo-specified variables.

src/cargo/lib.rs

index f80f38d2e83e0444ebc6cf151e1c71603cdc63e0..89baab02194bdba5ea8144083985b9120a8d83d4 100644 (file)
@@ -200,7 +200,14 @@ fn handle_cause(err: &CargoError, shell: &mut MultiShell) {
 }
 
 pub fn version() -> String {
-    format!("cargo {}", env!("CFG_VERSION"))
+    format!("cargo {}", match option_env!("CFG_VERSION") {
+        Some(s) => s.to_string(),
+        None => format!("{}.{}.{}{}",
+                        env!("CARGO_PKG_VERSION_MAJOR"),
+                        env!("CARGO_PKG_VERSION_MINOR"),
+                        env!("CARGO_PKG_VERSION_PATCH"),
+                        option_env!("CARGO_PKG_VERSION_PRE").unwrap_or(""))
+    })
 }
 
 fn flags_from_args<T: FlagParser>(args: &[String],